//  2  Pick+ Record 结合应用【真实应用场景】
// 应用场景：Todo事项编辑或更新才需要填写描述信息,预览页面只提供标题和完成状态
// 因为编辑有描述信息【]信息, 所以不能设置成可选属性。
// 预览时如何保证只description提取 Todo 接口的两个属性呢?
interface Todo {
  title: string
  completed: boolean
  description?: string
}

let todoList: Todo[] = [
  {
    title: '开发权限管理模块',
    completed: true,
    description: '使用Vue3+typescript来开发',
  },
  {
    title: '年会',
    completed: false,
    description: '12月29号上午开心酒店1楼105',
  },
]

type Record<T> = {
  [P in keyof any]: T
}
type Pick<T, K extends keyof T> = {
  [P in K]: T[P]
}

type todoRecordType = Record<Todo> // type todoRecord = {
let todoRecord: todoRecordType = {}
type Picktype = Pick<Todo, 'completed' | 'title'>
const flag = true
todoList.map((todo) => {
  if (flag) {
    let res: Picktype = { title: todo.title, completed: todo.completed }
    todoRecord[todo['title']] = res
  } else {
    todoRecord[todo['title']] = todo
  }
})
console.log(todoRecord)
export {}
